package com.example.demo.service.impl;

import com.example.demo.mapper.OrgMapper;
import com.example.demo.service.DemoTaskServer;
import com.example.demo.service.InsertData;
import org.apache.hc.core5.http.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.net.URISyntaxException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;
import java.util.List;


@Service
public class DemoTaskServerImpl implements DemoTaskServer {

    @Autowired
    OrgMapper orgMapper;

    @Autowired
    InsertData insertData;

    //定义任务执行的方法插入数据库数据
    public void insertData() throws Exception {
        String isAudit = "Y";
        String isSend = "Y";
        List<String> orgNameByLike = orgMapper.getOrgNameByLike("西华商品鸡%场");
        // 获取前一天的日期
        LocalDate yesterday = LocalDate.now().minusDays(1);

        LocalDate today = LocalDate.now();

        // 获取本月第一天
        LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("本月第一天: " + firstDayOfMonth);

        // 格式化输出（可选）
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = firstDayOfMonth.format(formatter);



        for (String name : orgNameByLike) {
            Integer orgId = orgMapper.getOrgIdByOrgName(name);
            int i = insertData.insertDieChicken(formattedDate, name, isAudit, isSend, orgId);
            System.out.println(name+" " + orgId + " "  + i);
        }




    }
}
